﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public partial class ZRoleAnim : MonoBehaviour {
    
    Animator m_Animator;
    public Animator animator
    {
        get
        {
            if(m_Animator == null)
                m_Animator = GetComponentInChildren<Animator>();

            return m_Animator;
        }
        set
        {
            m_Animator = value;
        }
    }

    /// <summary>
    /// default local position
    /// </summary>
    public float rcStandPosY;

    private void Awake()
    {

    }

    private void Start()
    {

    }


    private void OnDestroy()
    {
      
    }

    public void PlayAnim(string state, float progress)
    {
        PlayAnim(state, 0, progress);
    }


    /// <summary>
    /// 直接播放动画
    /// </summary>
    /// <param name="anim"></param>
    void PlayAnim(string anim)
    {
        if (string.IsNullOrEmpty(anim)) { return; }
        
        AnimatorPlay(anim);
    }
    public void PlayAnim(string anim, int layer, float time)
    {
        PlayAnim(anim, layer, time,true);
    }
    public void PlayAnim(string anim, int layer, float time,bool _playbackMode)
    {
        if (string.IsNullOrEmpty(anim)) { return; }
        
        AnimatorPlay(anim, layer, time);
        
    }




    public void ResetAnimatorTrigger(string paramName)
    {
        if(animator != null)
            animator.ResetTrigger(paramName);
    }

    public void SetAnimatorTrigger(string paramName)
    {
        if (animator != null)
            animator.SetTrigger(paramName);
    }
    public void SetAnimatorBool(string paramName,bool value)
    {
        if (animator != null)
            animator.SetBool(paramName, value);
    }
    public void SetAnimatorInteger(string paramName, int value)
    {
        if (animator != null)
            animator.SetInteger(paramName, value);
    }
    public void SetAnimatorFloat(string paramName, float value)
    {
        if (animator != null)
        {
            if(animator.parameters.AllWhere(e=>e.name.Equals(paramName)).AsList().Count > 0)
                animator.SetFloat(paramName, value);
        }
    }
    void AnimatorPlay(string anim)
    {
        AnimatorPlay(anim,0,0);
    }
    void AnimatorPlay(int animhash)
    {
        AnimatorPlay(animhash, 0, 0);
    }
    void AnimatorPlay(int animhash, int layer, float normalizeTime)
    {
        if (animator != null)
            animator.Play(animhash, layer, normalizeTime);
    }
    void AnimatorPlay(string anim,int layer,float normalizeTime)
    {
        if (animator != null)
            animator.Play(anim, layer, normalizeTime);
    }

    // Update is called once per frame
    void Update ()
    {


    }


}

